package net.zjitc.mapper;

import net.zjitc.po.Orders;
import net.zjitc.po.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * Created by Administrator on 2018/1/3.
 */
/*使用注解方式完成增删改查*/
public interface UserAnnotationMapper {
    //添加一个用户
    @Insert("insert into user(username,birthday,sex,address)value(#{username},#{birthday},#{sex},#{address})")
     @Options(useGeneratedKeys = true,keyProperty = "id")
    void addUser(User user);
    @Select("select * from user")
    List<User> findAllUser();
    @Results(
            {
                    @Result(id=true,column = "uid",property = "id"),
                    @Result(column = "un",property = "username")
            }
    )
    @Select("select * from user where id=#{id}")
   User findById(@Param("id")int uid);
    @Select("select * from orders where id=#{id}")
    @Results(
            {
                    @Result(id=true,column = "id",property = "id"),
                    @Result(column = "user_id",property = "user_id"),
                    @Result(column = "number",property = "number"),
                    @Result(column = "createtime" ,property = "createtime")
                    @Result(column = "note",property = "note"),
                    @Result(property = "user",column = "user_id",
                    one=@One(
                            select = "net.zjitc.mapper.UserAnnotationMapper.findById",
                            fetchType = FetchType.LAZY
                    )
                    ),
                    @Result(property = "ordersItemList",column = "id",
                    many=@Many(select="",fetchType = FetchType.LAZY)
                    )
            }
    )
  Orders findByOrdersId(int id);

}
